package com.leonardo.beanme.fields.abs;

import MAR.Core.Reflector;

import com.leonardo.beanme.BeanmeUtils;
import com.leonardo.beanme.OptionList;
import com.leonardo.beanme.model.BeanForm;

public abstract class ChoiceBox extends ChoiceInput {

	protected OptionList options;
	protected boolean lock;
	
	public ChoiceBox(int type) {
		super(type);
	}

	protected OptionList getOptions() {
		return options;
	}

	protected void setOptions(OptionList options) {
		this.options = options;
	}
	
	public void setName(String name) {
		Class type = BeanForm.getType();
		Reflector obj;
		try {
			obj = (Reflector) type.newInstance();
			setOptions((OptionList) obj.invokeMethod(BeanmeUtils.getGetterStr(name), null));
			for(int i = 0; i < options.getOptions().length; i++)
				addOption(options.getOptions()[i]);
		} catch(Exception ex) {
			ex.printStackTrace();
		}
	}
	
	public Object getValue() {
		options.select(getGroup().getSelectedIndex());
		return options;
	}
	
	public void lock() {
		lock = true;
	}
	
	public void unlock() {
		lock = false;
	}
	
}
